import random
import time

import requests

from Common.basepage import BasePage
from PageObjects.Main_page import MainPage
from PageObjects.Player_page import PlayerPage
from DP_invite_stress import start_invite


def player_stress():
    player_page = PlayerPage("d_one")
    operations = {
        "next": (player_page.click_next, 5),
        "play": (player_page.click_play, 2),
        "schedule": (player_page.click_random_schedule, 5),
        "rate": (player_page.click_random_rate, 5),
        "bit": (player_page.click_random_bit, 5)
    }

    operate = random.choices(list(operations.keys()), weights=(2, 1, 2, 2, 2), k=1)[0]
    operation, delay = operations[operate]
    operation()
    time.sleep(delay)


def DP_stress():
    PlayerPage("d_one").open_video_by_SCHEME(qipuId="406386200")
    time.sleep(2)
    PlayerPage("d_one").click_share()
    time.sleep(1)
    PlayerPage("d_one").click_slave_invite()
    time.sleep(1)
    PlayerPage("d_one").click_ok()
    time.sleep(2)
    while True:
        try:
            player_stress()
        except:
            # requests.get(url="https://api.day.app/s3KoLFVvWVWdYiiro2gKW/CX1E自动操作脚本可能出现问题")
            pass


if __name__ == '__main__':
    # PlayerPage("d_one").open_video_by_SCHEME(qipuId="406386200")
    MainPage("d_one").start_IQIYI_app()
    time.sleep(2)
    MainPage("d_one").click_first_television()
    start_invite()
    time.sleep(6)
    while True:
        try:
            player_stress()
        except:
            try:
                BasePage("d_one").press_key("back")
                time.sleep(1)
                BasePage("d_one").press_key("back")
                MainPage("d_one").start_IQIYI_app()
                time.sleep(2)
                MainPage("d_one").click_first_television()
                start_invite()
                time.sleep(6)
                # requests.get(url="https://api.day.app/s3KoLFVvWVWdYiiro2gKW/CX1E自动操作脚本可能出现问题")
                pass
            except:
                pass
